package com.ymatou.iapi.godmch.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.dguser.parameter.UserCreateBean;
import com.ymatou.iapi.godmch.parameter.applyAgentBean;
import com.ymatou.iapi.godmch.parameter.approveAgentBean;
import com.ymatou.iapi.godmch.parameter.createIndepMchBean;
import com.ymatou.iapi.godmch.parameter.getMarketPriceConfigBean;
import com.ymatou.iapi.godmch.parameter.setMarketPriceConfigBean;
import com.ymatou.iapi.godmch.service.applyAgentCall;
import com.ymatou.iapi.godmch.service.createIndepMchCall;
import com.ymatou.iapi.godmch.service.getMarketPriceConfigCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.DGUserCallService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.godmch.mch_config;
import com.ymttest.database.model.godmch.mch_configExample;
import com.ymttest.database.sqlwapper.godmch.mch_configWapper;
/**
*获取市场价配置
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_getMarketPriceConfig{
	private static getMarketPriceConfigBean bean;
	private static getMarketPriceConfigCall call;
	private mch_configWapper mchconfigWapper;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取市场价配置");
	}

	@Before
	public void caseUp() {
		bean=new getMarketPriceConfigBean();
		call=new getMarketPriceConfigCall();
		mchconfigWapper=new mch_configWapper(); 	
		}
	

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	private void check_verify(setMarketPriceConfigBean setMarketPriceConfigBean) throws InterruptedException
	{
		mch_configExample example=new mch_configExample();
        example.createCriteria().andMchIdEqualTo(bean.getMchId());
        mch_config mchconfig=mchconfigWapper.selectByExample(example).get(0);
        
		Logger.verifyEquals("200", call.getStatus1(), "验证status");
		Logger.verifyEquals("请求成功", call.getMessage(), "验证Message");
		Logger.verifyEquals( setMarketPriceConfigBean.getMarketPriceEnabled(), mchconfig.getMarketPriceEnabled(), "验证数据库中marketPriceEnabled字段的值是否正确");
		Logger.verifyEquals(setMarketPriceConfigBean.getMarketPriceTitle()==null?"市场价":setMarketPriceConfigBean.getMarketPriceTitle(), mchconfig.getMarketPriceTitle(), "验证数据库中marketPriceTitle字段的值是否正确");
		Logger.verifyEquals(true, mchconfig.getMarketPriceEnabled(), "验证数据库中mchInfoEnabled字段的值是否正确");
		
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getMarketPriceConfig_001() {
		Logger.start(true,"正例-获取市场价配置-平台商户-返回成功");
		try {
			setMarketPriceConfigBean setMarketPriceConfigBean=GodmchManageCallService.initSetMarketPriceBean();
			GodmchManageCallService.setMarketPriceCall(setMarketPriceConfigBean);
			bean.setMchId(setMarketPriceConfigBean.getMchId());
			call.setData(bean);
			call.callService();			
			
			check_verify( setMarketPriceConfigBean);
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getMarketPriceConfig_002() {
		Logger.start(true,"正例-获取市场价配置-独立商户-返回成功");
		try {
			createIndepMchBean createIndepMchBean=GodmchManageCallService.InitCreateIndepMchBean();
			createIndepMchCall createIndepMchCall=GodmchManageCallService.CreateIndepMchCall(createIndepMchBean);
			
			setMarketPriceConfigBean setMarketPriceConfigBean=GodmchManageCallService.initSetMarketPriceBean(createIndepMchCall.getmchId());
			GodmchManageCallService.setMarketPriceCall(setMarketPriceConfigBean);
			bean.setMchId(setMarketPriceConfigBean.getMchId());
			call.setData(bean);
			call.callService();			
			
			check_verify( setMarketPriceConfigBean);		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getMarketPriceConfig_003() {
		Logger.start(true,"正例-获取市场价配置-平台商户代理-返回成功");
		try {
			//渠道
			Integer userId_channl=GodmchManageCallService.CreateSellerMch();
			//代理
			UserCreateBean usercreateBean1=DGUserCallService.initUsercreateBean();
			int userId_agent=DGUserCallService.UserCreateCall(usercreateBean1);
			
			setMarketPriceConfigBean setMarketPriceConfigBean=GodmchManageCallService.initSetMarketPriceBean(userId_agent);
			GodmchManageCallService.setMarketPriceCall(setMarketPriceConfigBean);
			bean.setMchId(setMarketPriceConfigBean.getMchId());
			call.setData(bean);
			call.callService();			
			
			check_verify( setMarketPriceConfigBean);		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getMarketPriceConfig_004() {
		Logger.start(true,"正例-获取市场价配置-独立商户代理-返回成功");
		try {
			createIndepMchBean createIndepMchBean=GodmchManageCallService.InitCreateIndepMchBean();
			createIndepMchCall createIndepMchCall=GodmchManageCallService.CreateIndepMchCall(createIndepMchBean);
			
			approveAgentBean approveAgentBean=GodmchManageCallService.InitApproveAgentBean();
			
			setMarketPriceConfigBean setMarketPriceConfigBean=GodmchManageCallService.initSetMarketPriceBean(approveAgentBean.getAgentId());
			GodmchManageCallService.setMarketPriceCall(setMarketPriceConfigBean);
			bean.setMchId(setMarketPriceConfigBean.getMchId());
			call.setData(bean);
			call.callService();			
			
			check_verify( setMarketPriceConfigBean);		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getMarketPriceConfig_005() {
		Logger.start(true,"正例-获取市场价配置-mchId不存在-返回成功");
		try {
			setMarketPriceConfigBean setMarketPriceConfigBean=GodmchManageCallService.initSetMarketPriceBean();
			GodmchManageCallService.setMarketPriceCall(setMarketPriceConfigBean);
			bean.setMchId(setMarketPriceConfigBean.getMchId()+9999);
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("200", call.getStatus1(), "验证status");
			Logger.verifyEquals("请求成功", call.getMessage(), "验证Message");
			Logger.verifyEquals( false,call.getMarketPriceEnabled(), "验证数据库中marketPriceEnabled字段的值是否正确");
			Logger.verifyEquals("",call.getMarketPriceTitle(), "验证数据库中marketPriceTitle字段的值是否正确");		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getMarketPriceConfig_006() {
		Logger.start(true,"正例-获取市场价配置-mchId为空-返回成功");
		try {
			
			//bean.setMchId(setMarketPriceConfigBean.getMchId()+9999);
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("4001", call.getStatus1(), "验证status");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getMarketPriceConfig_007() {
		Logger.start(true,"正例-获取市场价配置-平台商户-验证商详页是否显示商户详情-返回成功(新增字段 mchInfoEnabled=false,默认true 20200527)");
		//上线后需批量处理数据
		try {

//			setMarketPriceConfigBean setMarketPriceConfigBean=GodmchManageCallService.initSetMarketPriceBean();
//			GodmchManageCallService.setMarketPriceCall(setMarketPriceConfigBean);
			bean.setMchId(500995165);
			call.setData(bean);
			call.callService();			
			
			mch_configExample example=new mch_configExample();
		    example.clear();
	        example.createCriteria().andMchIdEqualTo(bean.getMchId());
	       
	        mch_config mchconfig=mchconfigWapper.selectByExample(example).get(0);
			Logger.verifyEquals("200", call.getStatus1(), "验证status");
			Logger.verifyEquals("请求成功", call.getMessage(), "验证Message");
			Logger.verifyEquals(false, mchconfig.getMchInfoEnabled(), "验证数据库中mchInfoEnabled字段的值是否正确");
			Logger.verifyEquals(true, mchconfig.getMarketPriceEnabled(), "验证数据库中MarketPriceEnabled字段的值是否正确");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}